﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApp4.DLL;

namespace WindowsFormsApp4
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        DbUse dbUse = new DbUse();
  
        private void button2_Click(object sender, EventArgs e)
        {
            RegisterForm registerForm = new RegisterForm();
            registerForm.Show();
            this.Hide();
        }
         
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbnLogin_Click(object sender, EventArgs e)
        {
            string UserName = tbUsername.Text.Trim();
            string PassWord = tbPassword.Text.Trim();


            if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(PassWord))
            {
                bool ds = dbUse.OnLogin(UserName, PassWord);

                if (ds)
                {
                    MainForm mainForm = new MainForm();
                    this.Hide();
                    mainForm.Show();
                }
                else
                {
                    MessageBox.Show("账号或密码错误");
                }
            }
            else {
                MessageBox.Show("账号或密码不能为空");
            }
        }
    }
}
